﻿using lib472.Model.code;
using lib472.Model.Frm;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using static lib472.EdiTypes;

namespace lib472
{
    public static class DataCatkini
    {
        private const string DataCatkName = "DataCatk.ini";
        private static IniFile ini = new IniFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), DataCatkName));

        public static string GetString(string section, string key, string def)
        {
            return ini.GetString(section, key, def);
        }

        public static int GetInt(string section, string key, int def)
        {
            return ini.GetInt(section, key, def);
        }

        public static void WriteInt(string section, string key, int iVal)
        {
            ini.WriteInt(section, key, iVal);
        }

        public static void WriteString(string section, string key, string strVal)
        {
            ini.WriteString(section, key, strVal);
        }

        public static bool GetBool(string section, string key, bool Default)
        {
            return ini.GetBool(section, key, Default);
        }

        public static void WriteBool(string section, string key, bool Value)
        {
            ini.WriteBool(section, key, Value);
        }


        public static string GetTransSetup(importExportKind key)
        {
            return ini.GetString("importExportKind", $"{key}", string.Empty);
        }

        public static void WriteTransSetup(importExportKind key, string vaules)
        {
            ini.WriteString("importExportKind", $"{key}", vaules);
        }

        public static importExportKind FromSelectimportExportKind
        {
            get { return (importExportKind)ini.GetInt("importExportKind", "FromSelectimportExportKind", 0); }
            set { ini.WriteInt("importExportKind", "FromSelectimportExportKind", (int)value); }
        }

        public static CatkArgs GetCatkArgs
        {
            get
            {
                CatkArgs args = new CatkArgs();
                args.ApplicationPath = ini.GetString("CATK", "applicationpath", "");
                args.Nub = ini.GetString("CATK", "nub", "");
                args.Code = ini.GetString("CATK", "code", "");
                args.Pass = ini.GetString("CATK", "pass", "");
                args.recapplicationPath = ini.GetString("CATK", "recapplicationPath", "");
                args.outXmlPath = ini.GetString("CATK", "outXmlPath", "");
                args.tempXmlPath = ini.GetString("CATK", "tempXmlPath", "");
                return args;
            }
            set {

                ini.WriteString("CATK", "applicationpath", value.ApplicationPath);
                ini.WriteString("CATK", "nub", value.Nub);
                ini.WriteString("CATK", "code", value.Code);
                ini.WriteString("CATK", "pass", value.Pass);
                ini.WriteString("CATK", "recapplicationPath", value.recapplicationPath);
                ini.WriteString("CATK", "outXmlPath", value.outXmlPath);
                ini.WriteString("CATK", "tempXmlPath", value.tempXmlPath);

            }
        }
    }
}
